package com.example.demo;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2025-05-06
 * Time: 17:39
 */
@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session){
        //1.参数校验
        //2.比较
        //3.返回值
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)){
            return false;
        }
        if ("111".equals(userName) && "123".equals(password)){
            session.setAttribute("loginUser",userName);
            return true;
        }
        return false;
    }
    @RequestMapping("/getLoginUser")
    public String getLoginUser(HttpServletRequest request){
        HttpSession session=request.getSession(false);
        if (session==null){
            return "";
        }
        return (String) session.getAttribute("loginUser");
    }
}
